<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<link href="${pageContext.request.contextPath}/css/org_manager.css"
	rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/add_new_org.css"
	rel="stylesheet" type="text/css" />
<jsp:useBean id="edittingUser" class="team02.server.bean.UserBean"
	scope="page"></jsp:useBean>
<jsp:setProperty property="*" name="edittingUser" />

<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
System.out.println(request.getParameter("name"));
//権限をチェックする
if(userBean.getAccessLevel()!=2){
	response.sendRedirect("404.html");
	return;
}
%>
<script>
	function error() {
		alert("新規ユーザが追加できません");
	}
	function checkinput() {
		if (document.form.password.value != document.form.confirmPassword.value) {
			alert("パスワードと確認パスワードが違う");
			return false;
		}

		return true;
	}
</script>
<c:if test="${edittingUser.name != null}">
	<c:set var="insertResult" value="<%=edittingUser.insert()%>"></c:set>
	<c:choose>
		<c:when test="${0 == insertResult}">
			<c:redirect url="user_manager.t02"></c:redirect>
		</c:when>
		<c:otherwise>
			<script type="text/javascript" lang="javascript">
				error();
			</script>

		</c:otherwise>
	</c:choose>
</c:if>

<div class="menu1"><%@include file="/jsputils/menu.jsp"%>
	<div class = "greeting_message">
		<%@include file="/jsputils/greeting.jsp"%>
	</div>
</div>
<div class="container">
<form action="" method="post" name="form" id="user_add">
	<div class="menu">
		<p class="menu_label">新規ユーザ追加</p>
	</div>
		<table class="content_table">
			<tr>
				<td>
					<p class="label">名前 ：</p>
				</td>
				<td>
					<p class="input">
						<input type="text" required="required" name="name" value=""
							placeholder="例. Do Minh Khoi" /> <input type="hidden"
							name="alias" value="<%=userBean.getAlias()%>" />
					</p>
				</td>
			</tr>
			<tr>
				<td>
					<p class="label">ログイン名 ：</p>
				</td>
				<td>
					<p class="input">
						<input type="text" required="required" name="username"
							placeholder="例. khoidm" />
					</p>
				</td>
			</tr>

			<tr>
				<td>
					<p class="label">パスワード：</p>
				</td>
				<td>
					<p class="input">
						<input type="password" required="required" name="password"
							placeholder="例. 123aBc" />
					</p>
				</td>
			</tr>

			<tr>
				<td>
					<p class="label">パスワード再入力 ：</p>
				</td>
				<td>
					<p class="input">
						<input type="password" required="required" name="confirmPassword"
							placeholder="例. 123aBc" />
					</p>
				</td>
			</tr>
			<tr>
				<td>
					<p class="label">メール：</p>
				</td>
				<td>
					<p class="input">
						<input type="email" required="required" name="email"
							placeholder="例. abc@gmail.com" />
					</p>
				</td>
			</tr>
			<tr>
				<td>
					<p class="label">タイプ：</p>
				</td>
				<td>
					<p class="input">
						<input type="radio" name="accessLevel" value="3" checked="checked" />出題者
						<input type="radio" name="accessLevel" value="4" />採点者
					</p>
				</td>
			</tr>
			<tr>
			<td>
				<p class="submit" style="text-align: right;">
					<input type="submit" formaction="" name="btn" value="保存" onclick="return checkinput()"/>
				</p>
			</td>
			<td style="text-align: left;">
				<a href="user_manager.t02">キャンセル</a>
			</td>
		</tr>
		</table>
	</form>
</div>